package edu.xhu.adapters;

import java.util.ArrayList;

import com.bean.TeachingBean;

import edu.xhu.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class EduTeaNameListAdapter extends BaseAdapter{

	private ArrayList<TeachingBean> mTeachList;
	private LayoutInflater mInflater;
	
	public EduTeaNameListAdapter(Context context, ArrayList<TeachingBean> mTeachList){
		this.mInflater = LayoutInflater.from(context);
		this.mTeachList = mTeachList;
	}
	
	
	public int getCount() {
		if (null == mTeachList)
			return 0;
		return mTeachList.size();
	}

	public Object getItem(int position) {
		return null;
	}

	public long getItemId(int position) {
		return 0;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder;
		if (convertView == null){
			viewHolder		= new ViewHolder();
			convertView		= mInflater.inflate(R.layout.edu_namelist_item, null);
			viewHolder.stuNumber	= (TextView) convertView.findViewById(R.id.textview_stu_number);
			viewHolder.name	= (TextView) convertView.findViewById(R.id.textview_name);
			viewHolder.major	= (TextView) convertView.findViewById(R.id.textview_major);
			viewHolder.classes	= (TextView) convertView.findViewById(R.id.textview_classes);
			viewHolder.grades	= (TextView) convertView.findViewById(R.id.textview_grades);
			viewHolder.rebuild	= (TextView) convertView.findViewById(R.id.textview_rebuild_flag);
			viewHolder.credit	= (TextView) convertView.findViewById(R.id.textview_credit);
			viewHolder.remark   = (TextView) convertView.findViewById(R.id.textview_remark);
			
			convertView.setTag(viewHolder);
		}else {
			viewHolder = (ViewHolder) convertView.getTag();
		}
		
		TeachingBean bean = mTeachList.get(position);
		
		viewHolder.stuNumber.setText("学号：" + bean.number);
		viewHolder.name.setText("姓名：" + bean.name);
		viewHolder.classes.setText("班级：" + bean.clsName);
		viewHolder.major.setText("专业：" + bean.professionName);
		viewHolder.grades.setText("成         绩：" + bean.grade);
		viewHolder.credit.setText("学         分：" + bean.coursecredit);
		viewHolder.rebuild.setText("重修标记：" + bean.rebulid);
		
		if (bean.remark != null && !bean.remark.equals("")){
			viewHolder.remark.setVisibility(View.VISIBLE);
			viewHolder.remark.setText("备注：" + bean.remark);
		}else {
			viewHolder.remark.setVisibility(View.GONE);
		}
		
		if (getCount() == 1){
			convertView.setBackgroundResource(R.drawable.full_selector);
		}else {
			if (0 == position){
				convertView.setBackgroundResource(R.drawable.top_selector);
			}else if (getCount()-1 == position){
				convertView.setBackgroundResource(R.drawable.bottom_selector);
			}else {
				convertView.setBackgroundResource(R.drawable.middle_selector);
			}
		}
		
		return convertView;
	}

	class ViewHolder{
		public TextView stuNumber;			//学号
		public TextView name;				//姓名
		public TextView major;				//专业
		public TextView classes;			//班级
		public TextView grades;				//成绩
		public TextView credit;				//学分
		public TextView rebuild;			//重修标记
		public TextView remark;				//备注信息
	}
}
